#ifndef __NURBS_SURFACE_MESH_NURBS__
#define __NURBS_SURFACE_MESH_NURBS__

#include "mesh.h"
#include "dispatcher.h"

class Node;
#include "nurbspatch.h"

class NurbsSurfaceMesh : public Mesh {
public:
	NurbsSurfaceMesh() {};
	NurbsSurfaceMesh(size_t nodes, 
					 const std::vector< std::pair<std::string, Variant> >& vertexdata, 
					 const std::vector< std::pair<std::string, Variant> >& nurbsdata, 
					 const std::vector< boost::multi_array<size_t, 2> >& nurbsIndex,
					 const std::vector< std::pair<Knotvector, Knotvector> >& knotvector,
					 size_t p, size_t q);
	
	void Init(size_t nodes, 
			  const std::vector< std::pair<std::string, Variant> >& vertexdata, 
			  const std::vector< std::pair<std::string, Variant> >& nurbsdata, 
			  const std::vector< boost::multi_array<size_t, 2> >& nurbsIndex,
			  const std::vector< std::pair<Knotvector, Knotvector> >& knotvector,
			  size_t p, size_t q);
	
	virtual Node* GetNode(size_t i) {return vertex[i];}
	virtual const Node* GetNode(size_t i) const {return vertex[i];}
	
	virtual Element* GetElement(size_t i) {return nurbs[i];}
	virtual const Element* GetElement(size_t i) const {return nurbs[i];}
	
	virtual size_t SizeNodes() const {return vertex.size();}
	virtual size_t SizeElements() const {return nurbs.size();}

	virtual void Save(const std::string& filename, const std::string& attribute) const;
	
	Node* AllocateVertex();
	SNurbs* AllocateNurbs(const boost::multi_array<Node*, 2>& c, const Knotvector& U, const Knotvector& V, size_t p, size_t q);
		
	virtual void Dispatch(Dispatcher* d) {
		d->Visit(this);
	}
private:
	std::vector<Node*> vertex;
	std::vector<SNurbs*> nurbs;
	size_t vertexidcounter, nurbsidcounter;
};

#endif //__NURBS_SURFACE_MESH_NURBS__
